<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE>
<html>
<head>
	<title>SystemActivity</title>
	<%@ include file="/WEB-INF/views/include/head.jsp" %>
</head>
<body>
<%@ include file="/WEB-INF/views/include/loading.jsp" %>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center'">
		<form id="DataForm" method="post">
			<table style="width: 100%;">
				<tbody>
				<tr>
					<td style="width: 50%;hight:42px; padding: 5px; text-align: center;">
						<input class="easyui-combobox" id="userId" name="userId" value="" required="true" labelWidth="100" label="用户姓名" style="width: 90%;height:32px;line-height:32px;"
						       data-options="
	    						 			url:'${ctx}/user/user/getUserListByRealName',
	    						 			method:'post',
									        textField:'realname',
									        valueField:'id',
									        width:120,
									        mode:'remote',
											editable:true,
											hasDownArrow:false,
											limitToList:true,
									        prompt:'输入姓名自动匹配',
									        onBeforeLoad: function(param){
												if(param == null || param.q == null || param.q.replace(/ /g, '') == ''){
													var value = $(this).combobox('getValue');
													if(value){
														param.id = value;
														return true;
													}			
													return false;
												}
											}" >
					</td>
				</tr>
				<tr>
					<td style="width: 50%; padding: 5px; text-align: center;">
					<input class="easyui-combobox" id="carVin" name="carVin" value="" required="true" labelWidth="100" label="车架号" style="width: 90%;"
						       data-options="
											        url:'${ctx}/user/user/carVins',
											        textField:'text',
											        valueField:'text',
											        width:120,
											        panelHeight:'260',
											        editable:false,
											        prompt:'车架号'"> 
					</td>
				</tr>
				<tr>
					<td style="width: 50%; padding: 5px; text-align: center;">
						<input class="" hidden="true" id="activitySystemId" value="" name="activitySystemId" labelWidth="100" label="系统活动编号" data-options="prompt:'系统活动编号'" style="width: 90%;">
					</td>
					<td style="width: 50%; padding: 5px; text-align: center;">
						<input class="" hidden="true" id="appSign" value="" name="appSign" labelWidth="100" label="终端应用标识" data-options="prompt:'终端应用标识'" style="width: 90%;">
					</td>
				</tr>
				<tr>
					<td style="width: 50%; padding: 5px; text-align: center;">
						<input class="" hidden="true" hidden="true" id="creater" name="creater" value="${systemActivity.creater}" labelWidth="100" label="创建人" data-options="prompt:'创建人'" style="width: 90%;">
					</td>
					<td style="width: 50%; padding: 5px; text-align: center;">
						<input class="" hidden="true" id="createTime" name="createTime" value="${systemActivity.createTime}" labelWidth="100" label="创建时间" data-options="prompt:'创建时间'" style="width: 90%;">
					</td>
				</tr>
				<tr>
					<td style="width: 50%; padding: 5px; text-align: center;">
						<input class="" hidden="true" id="modifier" name="modifier" value="${systemActivity.modifier}" labelWidth="100" label="修改人" data-options="prompt:'修改人'" style="width: 90%;">
					</td>
					<td style="width: 50%; padding: 5px; text-align: center;">
						<input class="" hidden="true" id="modifyTime" name="modifyTime" value="${systemActivity.modifyTime}" labelWidth="100" label="修改时间" data-options="prompt:'修改时间'" style="width: 90%;">
					</td>
				</tr>
				<tr>
					<td style="width: 50%; padding: 5px; text-align: center;">
						<input class="" hidden="true" id="version" name="version" value="${systemActivity.version}" labelWidth="100" label="版本" data-options="prompt:'版本'" style="width: 90%;">
					</td>
				</tr>
				<tr>
					<td style="width: 50%; padding: 5px; text-align: center;">
						<input class="" hidden="true" id="id" name="id" value="${systemActivity.id}" labelWidth="100" label="id" required="true" data-options="prompt:'id'" style="width: 90%;">
					</td>
				</tr>
				</tbody>
			</table>
		</form>
	</div>
	<div data-options="region:'south',border:false" style="text-align:right; padding:10px;">
		<a id="btnSave" href="javascript:void(0)" class="easyui-linkbutton button-success" style="width: 80px;">
			<i class="fa fa-check fa-lg"></i>&nbsp;&nbsp;保存
		</a>
		<a id="btnCancel" href="javascript:void(0)" class="easyui-linkbutton button-warning" style="width: 80px;">
			<i class="fa fa-remove fa-lg"></i>&nbsp;&nbsp;取消
		</a>
	</div>
</div>

<!-- js脚本，必须写在body中，tab的url加载模式只会异步加载body中的内容到tab中 -->
<script type="text/javascript">
	require(['jquery', 'common'], function ($) {
		var systemActivityId = "${id}";
		var identification = "${identification}";

		// 给保存按钮添加点击事件
		$("#btnSave").on('click', function () {
			var vinNo = $("#carVin").val();
			var userId = $("#userId").val();
			$.ajax({
				url: '${ctx}/activity/activity/partakeActivity',
				data: {
					systemActivityId : systemActivityId,
					identification : identification,
					vinNo : vinNo,
					userId : userId
				},
				type: 'post',
				dataType: 'json',
				success: function (json) {
					if (json && json.rtnCode == '00000000') {
						$.messager.alert('提示', json.rtnMsg, "success",function(){
							$("#btnSave").linkbutton('enable');
							hideDialog();
						});
					} else {
						$.messager.alert('提示', json.rtnMsg, "error",function(){
							$("#btnSave").linkbutton('enable');
						});
					}
				},
				error: function(){
					$("#btnSave").linkbutton('enable');
				}
			});
		});

		// 给保存按钮添加点击事件
		$("#btnCancel").on('click', function () {
			hideDialog();
		});
		
		//根据支付渠道选择支付类型
		$('#userId').combobox({  
		    onChange: function(value) {
			var userId = $("#userId").textbox("getValue");
				if(userId.trim() != ''){
					
					$.ajax({
	                    url: '${ctx}/user/user/carVins',
	                    data: {
	                    	userId: userId
	                    },
	                    type: 'post',
	                    dataType: 'json',
	                    success: function (json) {
	                    	var userCarsList = json.userCarsList;
	                    	
	                    	var data,json;
							data = [];
	                    	for (var i = 0; i < userCarsList.length; i++) {
	                    		data.push({"id":userCarsList[i].id,"text":userCarsList[i].vinCode});
							}
	                    	$("#carVin").combobox({editable:false});
							$("#carVin").combobox({data:data});
	                    }		
	            	});
				}
		    }
		});
	});
</script>
</body>
</html>